import 'package:flutter_screenutil/flutter_screenutil.dart';

import '../support_files/assets.gen.dart';

class JzxCdtItem {
  final int level;

  /// 解锁条件文本
  final String condition;

  /// 任务次数
  final int number;

  // 以下需要完成本地状态存储

  /// 已完成数量
  final int done;

  /// 是否升级为高级头像框
  final bool isUpgrade;

  JzxCdtItem(
    this.level,
    this.condition, {
    this.number = 0,
    this.done = 0,
    this.isUpgrade = false,
  })  : baseFrame = AssetGenImage('assets/images/ic_frame$level.png'),
        baseFramePadding =
            AssetGenImage('assets/images/ic_frame_padding$level.png'),
        advancedFrame =
            AssetGenImage('assets/images/ic_frame_upgrade$level.png'),
        levelIcon = AssetGenImage('assets/images/ic_level$level.png');

  /// 基础头像框
  final AssetGenImage baseFrame;
  final AssetGenImage baseFramePadding;

  /// 高级头像框
  final AssetGenImage advancedFrame;

  /// 等级图标
  final AssetGenImage levelIcon;

  /// 任务完成+1
  JzxCdtItem increment() {
    return copyWith(done: done + 1);
  }

  /// 升级
  JzxCdtItem upgrade() {
    return copyWith(isUpgrade: true);
  }

  /// 首页渲染坐标
  double get homeLeft => homePosi['left'] ?? 0;
  double get homeTop => homePosi['top'] ?? 0;
  Map<String, double> get homePosi {
    switch (level) {
      case 1:
        return {'left': 75.w, 'top': 437.w};
      case 2:
        return {'left': 213.w, 'top': 328.w};
      case 3:
        return {'left': 48.w, 'top': 237.w};
      case 4:
        return {'left': 213.w, 'top': 152.w};
      case 5:
        return {'left': 91.w, 'top': 37.w};
      default:
        return {'left': 0, 'top': 0};
    }
  }

  JzxCdtItem copyWith({
    int? level,
    String? condition,
    int? number,
    int? done,
    bool? isUpgrade,
  }) {
    return JzxCdtItem(
      level ?? this.level,
      condition ?? this.condition,
      number: number ?? this.number,
      done: done ?? this.done,
      isUpgrade: isUpgrade ?? this.isUpgrade,
    );
  }
}
